<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .outBox {
        width: 300px;
        height: 300px;
        overflow: scroll;
      }
      .innerBox {
        width: 100%;
        height: 1000px;
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <div class="outBox" id="box">
      <div class="innerBox"></div>
    </div>
  </body>
  <script>
    document.getElementById("box").addEventListener("scroll", function (e) {
      // console.log(e);
      let box = document.getElementById("box");
      // 1. 目前窗口可以滚动的高度
      let scrollHeight = box.scrollHeight;
      console.log("窗口可以滚动的高度:", scrollHeight);
      // 2. 已经滚动的距离
      let scrollTop = box.scrollTop;
      console.log("已经滚动的距离", scrollTop);
      // 3. 窗口本身的高度
      let clientHeight = box.clientHeight;
      console.log("窗口本身的高度", clientHeight);
      // 机器上的差异 导致值有时不是等于 0
      if (scrollHeight - scrollTop - clientHeight < 10) {
        console.log("已经触底了");
      }
    });
  </script>
</html>
